<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link href="css/table.css" rel="stylesheet" type="text/css" />
<link href="css/excite-bike/jquery-ui-1.8.22.custom.css" rel="stylesheet" type="text/css" />
<script src="js/jquery-1.7.2.min.js"></script>
<script src="js/jquery.MultiFile.pack.js"></script>
<script src="js/jquery.cookie.js"></script>
<script src="js/jquery-ui-1.8.22.custom.min.js"></script>
<script src="js/widgets.js"></script>


<script type="text/javascript">
$(document).ready(function() {
	$("#dialog-subTC").css("visibility", "hidden");			//送審測試案例
	$("#dialog-infoMR").css("visibility", "hidden");
	$("#loginUser")[0].value = $.cookie("userID");
	$("#sub_submittedBy")[0].value = "reviewer";	//為了使同一支程式，能交分辨提交人員的角色
	
	$.ajax({														
		type : "post",
		data : $("#q_form").serializeArray(),
		url : "ReviewTC",
		dataType : "JSON",
		success : function(queryResult) {
			var i=999;
			var m=0;
			if (queryResult.size > 0) {
				$.each(queryResult.sqlData, function(a, res) {
					var isReviewer = res.isReviewer;
					var tpid = res.tpid;
					var mrid = res.mrid;
					var ver = res.ver;
					var sourceid = res.sourceid;
					var mrdescription = res.mrdescription;
					
					
					var tester = "";
					if (res.tester != undefined) {
						$.each(res.tester,function(indexTester,user) {
							tester += "<li class=\"mrTestOwner\" nickName=\""+user.nickName+"\" val=\""+user.userID+"\">"+user.nickName+"</li>";
						});	
					}
					
					var ind = $("#mainTbody tr").length+1;
					var bgcolor=getbgColor(ind);

					var butText = "處理";
					
					if (!isReviewer) {
						butText ="檢視";
						$(".onlyForReviewer").remove();
					}
					$("#mainTbody").append("<tr id=\""+mrid+"\" sel=\""+i+"\" cont=\""+m+"\" isInDB=\"false\" class=\"inTmp\" ondblclick=\"trDoubleClick('"+i+"','"+m+"','"+mrid+"')\" bgcolor="+bgcolor+"><td>"+ind+"</td><td><input type=\"text\" size=\"21\" sel=\""+i+"\" cont=\""+m+"\" value=\""+sourceid+"\" attr=\"sourceid\" mrid=\""+mrid+"\" /></td><td><textarea id='"+mrid+"_mrDesc' sel=\""+i+"\" cont=\""+m+"\" attr=\"mrdescription\" mrid=\""+mrid+"\" onchange=\"updateMRItem(this)\" >"+mrdescription+"</textarea></td><td><ul id=\""+mrid+"_mrTester\" >"+tester+"</ul></td><td>"+df(1)+"</td><td id=\"lupt_"+mrid+"\">"+df(1)+"</td><td><button id='"+mrid+"_reviewTC' mrid=\""+mrid+"\" ver=\""+ver+"\" tpid=\""+tpid+"\" isReviewer=\""+isReviewer+"\" class='reviewTC' onClick=\"Click_reviewTC(this)\" type=\"button\">"+butText+"</button><button id='"+mrid+"_infoItem' mrid=\""+mrid+"\" ver=\""+ver+"\" tpid=\""+tpid+"\" tpname=\""+res.tpName+"\"  class='infoItem' onClick=\"Click_infoItem(this)\" type=\"button\">相關資訊</button></td></tr>");
				});
			}
		}
	});
});


function reviewTC(isAccepted) {
	$("#sub_isAccepted")[0].value = isAccepted;
	$("#sub_submitorComment")[0].value = $("#submitorComment").val();
	
	$.ajax({
		type : "post",
		url : "ReviewTC_ACT",
		data : $("#q_form").serializeArray(),
		dataType : "TEXT",
		success : function(res) {
			if (res =="OK") {
				alert("完成回覆");
			} else {
				alert("回覆失敗");
			}
		}
	});
}


function floyd(isReviewer) {
	//先清空舊有資料
	$("#ConfirmSubTC").html("");
	$.ajax({
		type : "post",
		url : "GetSelectedTC",
		data : $("#q_form").serializeArray(),
		dataType : "JSON",
		success : function(Result) {
			var tcuid =[];
			var size = Result.size;
			var comment = Result.comment;
			if (comment != "Noc") {
				$("#testerComment").val(comment);
			}
			
			$.each(Result.sqlData, function(i, res) {
				tcuid.push(res.uID);
				$("#ConfirmSubTC").append("<tr><th class=\"query\">測試識別代號：</th><td colspan=\"2\" class=\"query\"><input type=\"text\" value=\""
						+tcuid[i]+"\" disabled /></td><td rowspan=\"3\"></td></tr><tr><th class=\"query\">測試案例名稱：</th><td colspan=\"2\" class=\"query\"><input type=\"text\" value=\""
						+res.tcName+"\" disabled /></td></tr><tr><th class=\"query\">驗證重點數：</th><td colspan=\"2\" class=\"query\"><input type=\"text\" value=\""
						+res.numKeyPoint+"\" disabled /></td></tr><tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr><tr><th width=\"15%\">驗證重點</th><th width=\"15%\">測試資料</th><th width=\"15%\">測試程序</th><th width=\"15%\">預期結果</th></tr><tr><td id=\""+tcuid[i]+"_tcKeyPoint\">"
						+res.tcKeyPoint+"</td><td id=\""+tcuid[i]+"_tcTestData\">"
						+res.tcTestData+"</td><td id=\""+tcuid[i]+"_tcProcess\">"
						+res.tcProcess+"</td><td id=\""+tcuid[i]+"_tcResExp\">"
						+res.tcResExp+"</td><td><tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr><tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>");
			});
			$("#dialog-subTC").css("visibility", "visible");
			if (isReviewer=="true") {
				$("#dialog-subTC").dialog({
					resizable : true,
					width : 1300,
					height : 600,
					data : $("#q_form").serializeArray(),
					modal : true,
					buttons : {
						"同意" : function() {
							/** 將TextArea的實體刪除，否則後面再點開時會錯 **/
							var mrid = $("#sub_mrid")[0].value;
							$("#"+mrid+"_reviewTC").attr("disabled","disabled");
							reviewTC(1);
							$(this).dialog("close");
						},"拒絕" : function() {
							var mrid = $("#sub_mrid")[0].value;
							$("#"+mrid+"_reviewTC").attr("disabled","disabled");
							reviewTC(0);
							$(this).dialog("close");
						},"關閉" : function() {
							$(this).dialog("close");
						}
					}
				});	
			} else {
				$("#dialog-subTC").dialog({
					resizable : true,
					width : 1300,
					height : 600,
					data : $("#q_form").serializeArray(),
					modal : true,
					buttons : {
						"關閉" : function() {
							$(this).dialog("close");
						}
					}
				});
			}
			
			$("#dialog:ui-dialog").dialog("destroy");
			
		}, error : function(xhr, ajaxOptions, thrownError) {
			$("#errorMessage").html("錯誤訊息狀態：" + xhr.status+"<p>");
			$("#errorMessage").append(xhr.responseText);
		}
	});
}


/** 送審案例 **/
function Click_reviewTC(obj) {
	var mrid = $(obj).attr("mrid");
	$("#sub_mrid")[0].value = mrid;
	var tpid = $(obj).attr("tpid");
	$("#sub_tpid")[0].value = tpid;
	$("#sub_submittedBy")[0].value = "reviewer";
	var ver = $(obj).attr("ver");
	$("#sub_ver")[0].value = ver;
	var isReviewer = $(obj).attr("isReviewer");
	floyd(isReviewer);
}

</script>
</head>
<body>
<div id="tpBody">
	<table>
		<thead>
			<tr>
				<th>#</th>
				<th width="230">項目編號</th>
				<th><font face="標準體" color="#FF0000"><sub>*</sub></font>項目名稱</th>
				<th>測試負責人</th>
				<th>建立日期</th>
				<th>最後修改日期</th>
				<th>&nbsp;</th>
			</tr>
		</thead>
		
		<tbody id="mainTbody">
		</tbody>
	</table>
	</div>
	
	<div id="dialog-subTC" title="確認送審項目">
	<table>
		<tbody id="ConfirmSubTC">
		</tbody>
		
		<tfoot>
			<tr><th class="left" colspan="2">送審人員意見</th><td rowspan="2" colspan="2"></td></tr>
			<tr><td colspan="2"><textarea id="testerComment" cols="60" DISABLED></textarea></td><td></td></tr>
			
			<tr class="onlyForReviewer"><th class="left" colspan="2">意見</th><td rowspan="2" colspan="2"></td></tr>
			<tr class="onlyForReviewer"></tr>
			<tr class="onlyForReviewer"><td colspan="2"><textarea id="submitorComment" cols="60"></textarea></td><td></td></tr>
		</tfoot>
	</table>
	</div>
	
	<form id="q_form" method="post">
		<input type="hidden" id="sub_tpid" name="tpid" />					<!-- 測試案ID -->
		<input type="hidden" id="sub_mrid" name="mrid" />					<!-- 測試項目ID -->
		<input type="hidden" id="sub_submittedBy" name="submittedBy" />		<!-- 送出的角色為 -->
		<input type="hidden" id="sub_isAccepted" name="isAccepted" />		<!-- 同意還是拒絕 -->
		<input type="hidden" id="sub_ver" name="ver" />						<!-- 目前測試項目選擇案例的版次 -->
		<input type="hidden" id="loginUser" name="loginUser" />				<!-- 目前登入的使用者 -->
		<input type="hidden" id="sub_submitorComment" name="submitorComment" />				<!-- 送審者的意見 -->
	</form>
	
	<div id="dialog-infoMR" title="相關資訊">
		<p>
		
		<table>
		<tr><th width="50%">上傳附加檔案</th><th width="50%">簽核意見</th></tr>
		<tr><td>
			<form id="form_infoFileUpload" method="post" enctype="multipart/form-data" target="FileUpload" action="FileUpload">
				<input name="file" id="file2" size="27" type="file" class="multi" />
				<input type="hidden" id="infoLoginUserFileUpload" name="loginUser" />					<!-- 目前登入的使用者 -->
				<input type="hidden" id="infoTpidFileUpload" name="tpid" />						<!-- 測試案ID -->
				<input type="hidden" id="infoMridFileUpload" name="mrid" />						<!-- 測試項目ID -->
				<iframe id="FileUpload" name="FileUpload" src="" style="width:0;height:0;border:0px solid #fff;"></iframe>
			</form>
			<br/>
		<button onClick="Click_infoFileUpload()" type="button">上傳檔案</button>
		</td>
		<td>
		<form id="form_infoComment" method="post">
			<textarea id="textarea_infoComment"></textarea>
		</form>
		<br/><button onClick="Click_infoComment()" type="button">送出意見</button>
		
		</td>
		</tr>
		</table>
		
		<p>
		<p>
		<table width="100%">
			<tr><th class="query">計畫案</th><td colspan="5" id="info_tpName">&nbsp;</td></tr>
			<tr><th class="query">測試項目</th><td colspan="5" id="info_mrDesc">&nbsp;</td></tr>
			<tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
			<tr><th class="query">指派人員</th><td class="query" id="info_assignedTester"><ul id="mrTester"></ul></td></tr>
			<tr>
				<th class="query">指定案例</th><td id="info_assignedTC"><ul id="mrTC"></ul></td>
				<th class="query">送審案例</th><td id="info_subTC">&nbsp;</td>
				<th class="query">測試案例審核</th><td id="info_reviewTC">&nbsp;</td>
			</tr>
			<tr> 
				<th class="query">結果更新</th><td id="info_fillTR">&nbsp;</td>
				<th class="query">送審結果</th><td id="info_subTR">&nbsp;</td>
				<th class="query">測試結果審核</th><td id="info_reviewTR">&nbsp;</td>
			</tr>
		</table>
	
		<div id="infoAction"></div>
		<div id="infoComment"></div>
		<div id="infoFileUpload"></div>
	</div>
	<form id="form_fileDoload" method="post" target="FileDownload" action="FileDownload">
		<input type="hidden" id="sub_sn" name="sn" />			
		<iframe id="FileDownload" name="FileDownload" src="" style="width:0;height:0;border:0px solid #fff;"></iframe>
	</form>
</body>
</html>